//
//  ViewController.swift
//  粒子动画效果
//
//  Created by app on 2017/4/15.
//  Copyright © 2017年 app. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.backgroundColor = UIColor.black
        let emetterCell = CAEmitterCell()
        emetterCell.name = "fire"
        emetterCell.emissionLongitude = CGFloat(M_PI)
        emetterCell.velocity = -1  // 粒子速度 负数标识向上燃烧
        emetterCell.velocityRange = 50 // 粒子范伟
        emetterCell.emissionRange = 1.1 // 发射角度
        emetterCell.yAcceleration = -200 // 粒子Y轴加速度分量
        emetterCell.scaleSpeed = 1 // 比例方法超大火苗
        emetterCell.color = UIColor(red: 0.8, green: 0.4, blue: 0.2, alpha: 0.1).cgColor
        emetterCell.contents = UIImage(named: "fire")?.cgImage
        
        let emitterLayer = CAEmitterLayer()
        emitterLayer.position = view.center
        emitterLayer.emitterSize = CGSize(width: 50, height: 10)
//        renderMode:渲染模式：
        emitterLayer.renderMode = kCAEmitterLayerAdditive
//        emitterMode:发射模式
        emitterLayer.emitterMode = kCAEmitterLayerSurface
        emitterLayer.emitterCells = [emetterCell]
        view.layer.addSublayer(emitterLayer)
        
        
//        1）.birthRate 顾名思义没有这个也就没有effectCell，这个必须要设置，具体含义是每秒某个点产生的effectCell数量
        
//        2）.lifetime & lifetimeRange 表示effectCell的生命周期，既在屏幕上的显示时间要多长。
        emitterLayer.setValue(500, forKeyPath: "emitterCells.fire.birthRate")
        emitterLayer.setValue(1, forKeyPath: "emitterCells.fire.lifetime")
        
        
    }
}

